/**
 * 代理统一导出 - IntelliMark版
 */

// 导出所有代理
export * from './writingAgent'
export * from './agentExecutor'

// 导出代理类型
export type {
  AgentConfig,
  AgentResult,
  WritingTaskType,
  WritingContext,
  WritingTask,
  WritingAgentConfig,
} from '../types/agent'

// 导出便捷创建函数
export {
  createWritingAgent,
  defaultWritingAgent
} from './writingAgent'

export {
  createAgentExecutor,
  defaultAgentExecutor
} from './agentExecutor'

// 代理管理器
export class AgentManager {
  private static instance: AgentManager
  private agents: Map<string, any> = new Map()
  private executor: any

  private constructor() {
    this.executor = defaultAgentExecutor
    this.initializeDefaultAgents()
  }

  public static getInstance(): AgentManager {
    if (!AgentManager.instance) {
      AgentManager.instance = new AgentManager()
    }
    return AgentManager.instance
  }

  private initializeDefaultAgents(): void {
    // 注册默认代理
    this.registerAgent('writing', defaultWritingAgent)
  }

  public registerAgent(name: string, agent: any): void {
    this.agents.set(name, agent)
    this.executor.registerAgent(name, agent)
  }

  public getAgent(name: string): any {
    return this.agents.get(name)
  }

  public getAllAgents(): Map<string, any> {
    return new Map(this.agents)
  }

  public listAgents(): string[] {
    return Array.from(this.agents.keys())
  }

  public async executeWithAgent(
    agentName: string,
    task: any,
    options?: { priority?: number; timeout?: number }
  ): Promise<any> {
    return this.executor.executeTask(agentName, task, options)
  }

  // 便捷写作方法
  public async write(prompt: string, options?: any): Promise<string> {
    return this.executor.write(prompt, options)
  }

  public async polish(text: string, options?: any): Promise<string> {
    return this.executor.polish(text, options)
  }

  public async expand(text: string, options?: any): Promise<string> {
    return this.executor.expand(text, options)
  }

  public async continue(text: string, options?: any): Promise<string> {
    return this.executor.continue(text, options)
  }

  public async summarize(text: string, options?: any): Promise<string> {
    return this.executor.summarize(text, options)
  }

  // 获取执行器
  public getExecutor(): any {
    return this.executor
  }

  // 获取统计信息
  public getStats(): any {
    return {
      agents: this.agents.size,
      executor: this.executor.getStatus(),
      agentDetails: this.executor.getAgentStats(),
    }
  }
}

// 导出便捷函数
export const getAgentManager = (): AgentManager => {
  return AgentManager.getInstance()
}